<?php
/* script is intended to run by cronjob
 * 
 */

set_include_path(get_include_path(). PATH_SEPARATOR. 'inc/');
require_once 'inc/globals.secret.php';
function __autoload($class_name) {
  require_once $class_name.'.class.php';
}

function isValidEmail($email){
    return preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $email);
}

$address="";
// parse script arguments
for ($i=1; $i<$argc; $i++) {
  parse_str($argv[$i]);
}

if (!array_key_exists (1,$argv) || in_array ("-h", $argv) || !isValidEmail($address)) {
  echo "usage:   php ".$_SERVER["PHP_SELF"]." <parameters>\n";
  echo "example: php ".$_SERVER["PHP_SELF"]." address=my.address@host.com\n";  
  echo "\n";
  die;
}

$db = new db($dbparams["host"], $dbparams["user"], $dbparams["password"]);
$db->connect("va_stratlab");

$mailc=new mailcontents("Report ".date("Y-m-d"), $db);

echo $mailc->message();

mail($address, $mailc->subject(), $mailc->message(), $mailc->headers());

//$log = $db->query_dailylog(date("Y-m-d"));
//print_r($log);

$db->disconnect();

?>
